home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / ROM_Kernel_Manuals / Lib_examples / semaphore.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  906 b   |  26 lines

  1. /* A simple "do nothing" example of Exec signal semaphore use is shown   */
  2. /* below. When the semaphore is owned by a task, attempted access by     */
  3. /* other tasks will block.  A nesting count is maintained, so the        */
  4. /* current task can safely call ObtainSemaphore() on the same semaphore. */
  5. /*
  6. /* semaphore.c - Exec semaphore example - compile with lc -L semaphore.c */
  7. #include <exec/types.h>
  8. #include <exec/semaphores.h>
  9. #include <clib/exec_protos.h>
  10. #include <stdio.h>
  11.  
  12. #ifdef LATTICE
  13. int CXBRK(void)  { return(0); }  /* Disable Lattice CTRL/C handling */
  14. void chkabort(void) { return; }  /* really */
  15. #endif
  16.  
  17. struct SignalSemaphore LockSemaphore = {0};
  18.  
  19. VOID main(int argc,char *argv[])
  20. {
  21.     InitSemaphore(&LockSemaphore);
  22.     ObtainSemaphore(&LockSemaphore);  /* Task now owns the semaphore. */
  23.          ...
  24.     ReleaseSemaphore(&LockSemaphore); /* Task has released the semaphore. */
  25. }
  26.